package cn.wolfcode.wolf2world.web.controller;

import cn.wolfcode.wolf2world.domain.Travel;
import cn.wolfcode.wolf2world.query.TravelQueryObject;
import cn.wolfcode.wolf2world.service.DestinationService;
import cn.wolfcode.wolf2world.service.TravelService;
import cn.wolfcode.wolf2world.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author 杨兴健
 * @Date 2020-08-14 12:55
 */
@Controller
@RequestMapping("/travel")
public class TravelController {
    @Autowired
    private TravelService travelService;

    /**
     * 旅游日记高级查询
     * @param model
     * @param qo 查询条件
     * @return
     */
    @RequestMapping("/list")
    public Object query(Model model, @ModelAttribute("qo") TravelQueryObject qo) {
        Page<Travel> page = travelService.queryMgr(qo);
        model.addAttribute("page",page);
        return "travel/list";
    }


    /**
     * 新增或更新区域
     * @param travel
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Travel travel,HttpServletResponse response) {
        travelService.saveOrUpdate(travel);
        response.setContentType("application/json;charset:utf-8");
        return JsonResult.success();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        travelService.delete(id);
        return JsonResult.success();
    }

    @RequestMapping("/audit")
    @ResponseBody
    public Object audit(String id,Integer state) {
        travelService.audit(id,state);
        return JsonResult.success();
    }
    @RequestMapping("/up")
    @ResponseBody
    public Object up(String id,Integer state) {
        travelService.up(id,state);
        return JsonResult.success();
    }

    @RequestMapping("/getContentById")
    @ResponseBody
    public Object getContentById(String id) {
        Travel travel = travelService.get(id);
        return JsonResult.success(travel.getContent());
    }



}
